package org.dxw.resp;

import lombok.Data;
import org.dxw.common.enums.GlobalResultEnum;

/**
 * @description:
 * @author: dxw
 * @create: 2022-04-04 23:33
 **/

@Data
public class BaseResponse<T> {

    public BaseResponse() {
    }

    private String code;

    private String msg;

    private T data;

    public BaseResponse(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse(GlobalResultEnum.SUCCESS.getCode(), GlobalResultEnum.SUCCESS.getMsg(), data);
    }

    public static BaseResponse error(String msg) {
        return new BaseResponse(GlobalResultEnum.ERROR.getCode(), msg, null);
    }

    public static BaseResponse error(String code, String msg) {
        return new BaseResponse(code, msg, null);
    }

    public static BaseResponse error(GlobalResultEnum GlobalResultEnum) {
        return new BaseResponse(GlobalResultEnum.getCode(), GlobalResultEnum.getMsg(), null);
    }


}